package com.senmin.aPrinciple.a3DependenceInversionPrinciple.tdemo1;

/**
 * @className: demeter1
 * @author: xpj
 * @create: 2021/6/5
 * @description: 案例：请编写完成person消息的功能【用依赖倒置】 方式2：通过setter方法来实现依赖
 */
public class demo3 {
    public static void main(String[] args) {
        Changhong3 changhong = new Changhong3();
        OpenAndClose3  openAndClose =  new OpenAndClose3();
        openAndClose.setTv(changhong);
        openAndClose.open();
    }
}



//方式1通过接口来实现依赖
interface IOpenAndClose3 {
    public void open ();//抽象方法，
    public void setTv(ITV3 tv);
}

interface ITV3{
    public void play();
}

class Changhong3 implements ITV3{
    @Override
    public void play(){
        System.out.println("打开长虹电视打开");
    }
}

//实现接口
class OpenAndClose3 implements  IOpenAndClose3{
    public ITV3 tv;

    @Override
    public void setTv(ITV3 tv){
        this.tv = tv;
    }


    @Override
    public  void open(){
        this.tv.play();
    }
}



